home *** CD-ROM | disk | FTP | other *** search
/ Ham Radio 2000 #1 / Ham Radio 2000.iso / ham2000 / tcp_ip / tnos / tnos100s / arpdump.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-04-30  |  1.8 KB  |  81 lines

  1. /* ARP packet tracing routines
  2.  * Copyright 1991 Phil Karn, KA9Q
  3.  */
  4. #include <stdio.h>
  5. #include "global.h"
  6. #include "mbuf.h"
  7. #include "arp.h"
  8. #include "netuser.h"
  9. #include "trace.h"
  10.  
  11. #ifdef TNOS_68K
  12. #define fprintf traceprintf
  13. #endif
  14.  
  15. void
  16. arp_dump(fp,bpp)
  17. FILE *fp;
  18. struct mbuf **bpp;
  19. {
  20.     struct arp arp;
  21.     struct arp_type *at;
  22.     int is_ip = 0;
  23.     char tmp[25];
  24.  
  25.     if(bpp == NULLBUFP || *bpp == NULLBUF)
  26.         return;
  27.     fprintf(fp,"ARP: len %d",len_p(*bpp));
  28.     if(ntoharp(&arp,bpp) == -1){
  29.         fprintf(fp," bad packet\n");
  30.         return;
  31.     }
  32.     if(arp.hardware < NHWTYPES)
  33.         at = &Arp_type[arp.hardware];
  34.     else
  35.         at = NULLATYPE;
  36.  
  37.     /* Print hardware type in Ascii if known, numerically if not */
  38.     fprintf(fp," hwtype %s",smsg(Arptypes,NHWTYPES,arp.hardware));
  39.  
  40.     /* Print hardware length only if unknown type, or if it doesn't match
  41.      * the length in the known types table
  42.      */
  43.     if(at == NULLATYPE || arp.hwalen != at->hwalen)
  44.         fprintf(fp," hwlen %u",arp.hwalen);
  45.  
  46.     /* Check for most common case -- upper level protocol is IP */
  47.     if(at != NULLATYPE && arp.protocol == at->iptype){
  48.         fprintf(fp," prot IP");
  49.         is_ip = 1;
  50.     } else {
  51.         fprintf(fp," prot 0x%x prlen %u",arp.protocol,arp.pralen);
  52.     }
  53.     switch(arp.opcode){
  54.     case ARP_REQUEST:
  55.         fprintf(fp," op REQUEST");
  56.         break;
  57.     case ARP_REPLY:
  58.         fprintf(fp," op REPLY");
  59.         break;
  60.     case REVARP_REQUEST:
  61.         fprintf(fp," op REVERSE REQUEST");
  62.         break;
  63.     case REVARP_REPLY:
  64.         fprintf(fp," op REVERSE REPLY");
  65.         break;
  66.     default:
  67.         fprintf(fp," op %u",arp.opcode);
  68.         break;
  69.     }
  70.     fprintf(fp,"\n");
  71.     fprintf(fp,"sender");
  72.     if(is_ip)
  73.         fprintf(fp," IPaddr %s",inet_ntoa(arp.sprotaddr));
  74.     fprintf(fp," hwaddr %s\n",at->format(tmp,arp.shwaddr));
  75.  
  76.     fprintf(fp,"target");
  77.     if(is_ip)
  78.         fprintf(fp," IPaddr %s",inet_ntoa(arp.tprotaddr));
  79.     fprintf(fp," hwaddr %s\n",at->format(tmp,arp.thwaddr));
  80. }
  81.